package com.tk.component;


import com.fazecast.jSerialComm.SerialPort;
import com.fazecast.jSerialComm.SerialPortDataListener;
import com.fazecast.jSerialComm.SerialPortEvent;
import com.tk.service.SerialPortService;
import com.tk.utils.SpringBeanUtils;


public class SerialPortListener implements SerialPortDataListener {

    private static SerialPortService serialPortService;


    public SerialPortListener() {
        SerialPortListener.serialPortService = SpringBeanUtils.getBean(SerialPortService.class);
    }

    @Override
    public int getListeningEvents() { // 必须是return这个才会开启串口工具的监听
        return SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
    }

    @Override
    public void serialEvent(SerialPortEvent serialPortEvent) {
        serialPortService.handlerData();
    }
}


